// schema扩展相关文档请参阅：https://uniapp.dcloud.net.cn/uniCloud/jql-schema-ext.html
module.exports = {
	trigger: {
		afterRead: async function({
			collection,
			operation,
			where,
			field,
			result,
			userInfo
		} = {}) {
			if(result.data.length === 0){
				let config = {
					user_id:userInfo.uid,
					email:true,
					notification_center:true,
					weixin_official_accounts:true
				}
				const db = uniCloud.database();
				let res = await db.collection('uni-notification-config')
						.add(config).catch(e=>{
							console.error(e);
						})
				result.data = [config]
			}
		}
	}
}
